<?php
/**
 * 公共方法调用
 * Created by PhpStorm.
 * User: pc
 * Date: 2019/1/8
 * Time: 17:07
 */

namespace app\admin\controller;

use think\Controller;
use think\Db;

class GlobalFun extends Controller
{

    /**
     * 总管理员跳转选择公司列表
     * @param string $backtrack
     * @return bool|mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function choose($backtrack = '')
    {
        //获取总公司下的子公司列表
        $where['status'] = 1;
//        $where['pid'] = isession('user_id');
        $where['flag'] = 1;
        $where['type'] = 2;
        $company_ids = DB::name('user')->field('company_id')->where($where)->group('company_id')->select();
//        p($company_ids);die;
        //判断总公司下面是否存在子公司
        if (checkArr($company_ids) == false) {
            return false;
        }
        $company_id = join(',', array_unique(array_column($company_ids, 'company_id')));
        $company = DB::name('company')->where('id', 'in', $company_id)->select();
        foreach ($company as $key => $value) {
            $company[$key]['bar'] = 0;
            if ($value['use_capacity'] > 0) {
                $company[$key]['use_capacity'] = diskTransform($value['use_capacity']);
                $company[$key]['bar'] = getDiskBar($value['upload_capacity'], $value['use_capacity']);
            }
        }
        $this->assign('company', $company);
        $this->assign('backtrack', $backtrack);
    }

    /**
     * 选择属性信息
     */
    public function chooseShuxing()
    {
        $where['pid'] = 0;
        $where['level'] = 1;
        $shuxing = Db::name('platform_shuxing')->where($where)->order("odx asc")->select();
        $shuxing = arrayCombine($shuxing, 'id');
        $whereInfo['pid'] = ['neq', 0];
        $whereInfo['level'] = 2;
        $shuxingInfo = Db::name('platform_shuxing')->where($whereInfo)->order("odx asc")->select();
        if (checkArr($shuxingInfo)) {
            foreach ($shuxingInfo as $value) {
                isset($shuxing[$value['pid']]) && $shuxing[$value['pid']]['info'][] = $value;
            }
        }
        $ids = checkString(sget('id')) ? explode(',', sget('id')) : [];
        $this->assign('shuxing', $shuxing);
        $this->assign('ids', $ids);
        return $this->fetch(APP_PATH . request()->module() . '/view/public/chooseShuxing.html');
    }
}